<?php
/**
 * Article class to insert article into joomla. Add new article etc.
 * LICENSE:
 *
 * @copyright 2010 Association Management Center
 * @author    Rakesh Verma (rakesh.verma@dotsquares.com)
 * @version   2.0
 * @link
 * @since     File available since import script creation
 * @package   Joomla Article
 */

class article extends app_object{
     /**
	 * Constructor, loads class defaults
	 *
	 * @return article
	 */
     function article(){
          $fields = array(
          'title',
          'alias',
          'title_alias',
          'introtext',
          'fulltext',
          'state',
          'sectionid',
          'mask',
          'catid',
          'created',
          'created_by',
          'created_by_alias',
          'modified',
          'modified_by',
          'checked_out',
          'checked_out_time',
          'publish_up',
          'publish_down',
          'images',
          'urls',
          'attribs',
          'version',
          'parentid',
          'ordering',
          'metakey',
          'metadesc',
          'access',
          'hits',
          'metadata');

          $table    = "joomla_content";
          $id_field = 'id';
          parent::app_object($fields, $table, $id_field);

     }//end function

     /**
      * This function used to save html page content into joomla article table as article.
      *
      */
     function save(){
          $this->values['fulltext']           = ''   ;
          $this->values['state']              = 1;
          $this->values['mask']               = 0;
          $this->values['created']            = date("Y-m-d"); //'2009-08-13 09:08:27';
          $this->values['created_by']         = '62';
          $this->values['created_by_alias']   = 0;
          $this->values['modified']           = '';
          $this->values['modified_by']        = '';
          $this->values['checked_out']        = '';
          $this->values['checked_out_time']   = '';
          $this->values['publish_up']         = '';
          $this->values['publish_down']       = '';
          $this->values['images']             = '';
          $this->values['urls']               = 'show_title=link_titles=show_intro=show_section=link_section=show_category=link_category=show_vote=show_author=show_create_date=show_modify_date=show_pdf_icon=show_print_icon=show_email_icon=language=keyref=readmore=';
          $this->values['version']             = 0;
          $this->values['parentid']            = 0;
          //$this->values['metakey']           ='';
          //$this->values['metadesc']          ='';
          $this->values['access']              = 0;
          $this->values['hits']                = 0;
          $this->values['metadata']            = 'robots=author=';
          parent::save();
     }

    /**
     * This function is used to check home page setting. If one article is set as home page article
     * then this returns flag value 0 else 1
     *
     * @return boolean(0, 1)
     */
     function check_data_exist(){
          $flag    = 1;
          $result  = app_data::mysql_query("select * from joomla_menu where home=1");
          $res     = mysql_num_rows($result);
          if($res>0){
            $flag  = 0;
          }
          return $flag;
     }//end function

    /**
     * Check joomla menu table if an entry of same menu child has been exist . If yes then this return
     * that menu's primary key value
     *
     * @param string $pagename
     * @return integer primary key or 0
     */
     function ispage_exist($pagename){
          $flag    = 0;
          $result  = app_data::mysql_query("select id from joomla_menu where name='$pagename'");
          $res     = mysql_num_rows($result);
          if($res>0){
               $idarr  = mysql_fetch_array($result);
               $flag   = $idarr['id'];
          }
          return $flag;
     }//end function

    /**
     * Check redundency of data on received table parameter on given condition. If an entry exist
     * Then return that entry 's primary key.
     *
     * @param string $table
     * @param string $condition
     * @return integer primary key or 0
     */
     function check_data_availability($table,$condition=''){
          $flag    = 0 ;
          $result  = app_data::mysql_query("select * from ".$table.' '.$condition);
          $res     = mysql_num_rows($result);
          if($res>0){
               $idarr  = mysql_fetch_array($result);
               $flag   = $idarr['id'];
          }
          return $flag;
     }//end function

    /**
     * Insert joomla section of an article.
     *
     * @param string $section_title
     * @return integer section insertId
     */
     function insert_section($section_title){
          $qs = "insert into joomla_sections(title,name,alias ,image ,scope ,image_position ,description ,published ,checked_out ,ordering)
                 values('$section_title','$section_title','$section_title','','content','','',1,0,'1')";
          app_data::mysql_query($qs);
          $sectionId  = mysql_insert_id();
          return $sectionId;
     }

    /**
     * Insert joomla category of an article.
     *
     * @param string $cat_title
     * @param integer $sectionid
     * @return integer category insertId
     */
     function insert_category($cat_title,$sectionid){
          $qs = "insert into joomla_categories(parent_id ,title ,name  ,	alias ,	image ,	section, image_position ,description ,published ,checked_out ,ordering )
                       values('0','$cat_title','$cat_title','$cat_title','','$sectionid','','',1,0,'1')";
          app_data::mysql_query($qs);
          $catId   = mysql_insert_id();
          return $catId;
     }

     /**
      *  Insert joomla menu at different child level . Add type of menu, if not exist.
      *
      * @param string $pages //articlename
      * @param integer $artid //article primary key
      * @param array $urlarr // url array extract by forward slashes/
      * @param boolean $home
      */
      function insert_menu($pages,$artid,$urlarr,$home=0){
          $menutype = "mainmenu";
          $result   = app_data::mysql_query("select menutype from joomla_menu_types");
          $res      = mysql_num_rows($result);
          if($res>0){
               $idarr      = mysql_fetch_array($result);
               $menutype   = $idarr['menutype'];
          }else{
               $qs          = "insert into joomla_menu_types(menutype,title,description) values('$menutype','$menutype','$menutype')";
          }
          $parentId  = 0;
          $link      = 'index.php?option=com_content&view=article&id='.$artid;
          $arrlength = count($urlarr);

          ////////////////////////////////////////////////////////////////
          if($arrlength>3){
               for($n=3;$n<$arrlength; $n++){
                    if($n==($arrlength-1) ){

                         $pagename    = $pages;
                         $pageContent = $data;

                         //article save
                         $pagename   = $pages;
                         $link       = 'index.php?option=com_content&view=article&id='.$artid;
                         $qs  = "insert into joomla_menu(menutype,name,alias,link,type,published,parent,componentid,sublevel,ordering,home)
                    	  		          values('$menutype','$pagename','$pagename','$link','component','1','$parentId','20','$q','1','$home') ";
                         app_data::mysql_query($qs);
                         $parentId  = mysql_insert_id();
                    }else{
                         $pagename    = $urlarr[$n];
                         $menuid      = $this->ispage_exist($pagename);
                         if($menuid==0){
                              //article save
                              $link = 'index.php?option=com_content&view=article&id='.$artid;
                              $qs   = "insert into joomla_menu(menutype,name,alias,link,type,published,parent,componentid,sublevel,ordering,home)
                        	  		                 values('$menutype','$pagename','$pagename','$link','component','1','$parentId','20','$q','1','$home') ";
                              app_data::mysql_query( $qs);
                              $parentId       = mysql_insert_id();
                              $this->id_value ='';
                              $home           = 0;
                         }else {
                              $parentId  = $menuid;
                         }//end if-else
                    }
                    $q++; //variable is using for tree level
               }//end for

          }else{ //else arrlenght

               $qs   = "insert into joomla_menu(menutype,name,alias,link,type,published,parent,componentid,home)
            	  	        values('$menutype','$pages','$pages','$link','component','1','$parentId','20','$home') ";
               app_data::mysql_query( $qs);
               $parentId  = mysql_insert_id();
          }//end if - else

     }//end function

     /**
      * Add url for sh404 redirection. These URL redirect from index.php?articleid=... to
      * new clean URL.
      *
      * @param string $oldurl
      * @param string $newurl
      * @param string $aliasurl
      * @param string $htmlpagename //article title
      * @return integer redirection intertId
      */
     function add_redirection($oldurl,$newurl,$aliasurl,$htmlpagename){

          $qs   = "insert into joomla_redirection(oldurl,newurl)
         	       values('$oldurl','$newurl') ";
          app_data::mysql_query($qs);
          $parentId   = mysql_insert_id();
          $qs_alias   = "insert into  joomla_sh404sef_aliases(newurl,alias)
         	             values('$aliasurl','$oldurl')";
          app_data::mysql_query($qs_alias);
          return $parentId;
     }//end function

     /**
      * Extract meta description, keyword, html from html page source code.
      *
      * @param string $store
      * @return //array meta tags array
      */
     function extract_meta($store){
          $ok = 1;
          $title = '';
          $description = '';
          $keywords = '';
          /*We extract the Title from the head tags:*/
          preg_match("/<head.*>(.*)<\/head>/smUi",$store, $headers);
          if(count($headers) > 0){
               /*Fetch the charset of the page*/
               if(preg_match("/<meta[^>]*http-equiv[^>]*charset=(.*)(\"|')>/Ui",$headers[1], $results)){
                   $charset= $results[1];
               }else{
                   $charset='None';
               }

               if(preg_match("/<title>(.*)<\/title>/Ui",$headers[1], $titles)){
                    if(count($titles) > 0){
                         /*If the charset information has been extracted, we convert it to UTF-8 - Otherwise we assume it's already UTF-8*/
                         if($charset == 'None'){
                            $title=trim(strip_tags($titles[1]));
                         }else{
                            $title=trim(strip_tags(iconv($charset, "UTF-8", $titles[1])));
                         }
                    }else{
                         /*If there is no title given we take the url as a title*/
                         if(strlen($url) > 30){
                            $title=trim(substr($url,30)).'...';
                         }else{
                            $title= trim($url);
                         }
                    }//end if -else
               }else {
                    /*If there is no title given we take the url as a title*/
                    if(strlen($url) > 30){
                        $title=trim(substr($url,30)).'...';
                    }else{
                        $title= trim($url);
                    }
               }//end if - else pregh match

          } //if end header tags

          /*Let's fetch the META description or give a description is there is not description available*/
          preg_match("|<meta[^>]*description[^>]*content=\"([^>]+)\"[^>]*>|Ui",$headers[1], $matches);
          if(count($matches) > 0){
               if($charset != 'None'){
                    $description= trim(strip_tags(iconv($charset, "UTF-8",$matches[1])));
               }else{
                    $description= trim(strip_tags($matches[1]));
               }

          }//end if

          /*Now the META keywords or some keywords which we extract from the description*/
          preg_match("|<meta[^>]*keywords[^>]*content=\"([^>]+)\"[^>]*>|Ui",$headers[1], $matches);
          if(count($matches) > 0)
          {
               if($charset != 'None'){
                    $keywords= trim(strip_tags(iconv($charset, "UTF-8",$matches[1])));
               }else{
                    $keywords= trim(strip_tags($matches[1]));
               }

          }
          else
          {
               /*We shall avoid the stopwords from the keywords*/
               $stopwords= array(' the ',' in ',' a ',' and ',' an ',' of ',' about ',' are ',' as ',' at ',' be ',' by ',' com ',' de ',' en ',' for ',' from ',' how ',' in ',' is ',' it ',' la ',' on ',' or ',' that ',' this ',' to ',' was ',' what ',' when ',' where ',' who ',' will ',' with ',' und ',' www ',' you ',' your ',' our ');
               $keywords=str_replace($stopwords," ",strtolower($description));
               $keywords=str_replace(" ",",",$keywords);

          }
          $meta_arr[0] = $title;
          $meta_arr[1] = $description;
          $meta_arr[2] = $keywords;
          return $meta_arr;
     }//end function

     /**
      * Add article into joomla content table. Section, category, menu insertion take place on
      * new article addtion.
      *
      * @param string $url
      * @param string $data //Only body content of page's html
      * @param string $header //Extract header by template
      * @param string $footer //Extract footer by template
      * @param boolean $home //Set 1 if article set as home page else 0
      * @param string $datas //Complete page html
      * @param boolean $istitle //if html title set as article title this parameter contain value 1
      * @param string $csvtitle //page titles of csv file set as article title if parameter is not blank
      */
     function add_article($url,$data,$header,$footer,$home=0,$datas='',$istitle='',$csvtitle=''){
          $urlarr      = explode("/",$url);
          $arrlength   = count($urlarr);
          $parentId    = 0;
          $menuId      = 2;
          $q           =  0;
          $inurl       = APP_URL;
          $urlcase     = $arrlength - 3;
          //echo htmlentities($data);

          switch($urlcase)
          {
               case 3:
                    //section insertion
                    $section_title = $urlarr[3];

                    $section_id    = $this->check_data_availability('joomla_sections'," where title ='".$section_title."'");
                    if($section_id==0){
                        $section_id = $this->insert_section($section_title);
                    }
                    //category insertion.
                    $category_title = $urlarr[4];
                    $category_id    = $this->check_data_availability('joomla_categories'," where title ='".$category_title."' and section=".$section_id);
                    if($category_id==0){
                        $category_id   = $this->insert_category($category_title,$section_id);
                    }
                    //page insertion
                    $pagename                     = $urlarr[5];
                    $pagename                     = substr($pagename,0,strrpos($pagename,'.'));
                    $pagehome                     = substr($pagename,0,strrpos($pagename,'.'));
                    if($pagename=='' || $pagename=='index'){
                         $pagetitle = $urlarr[4]."-".'index';
                         $pagename  = 'index';
                    } else{
                         $pagetitle = $pagename;
                    }
                     //grab metadata array
                    $metadataarr = $this->extract_meta($datas);

                    if($istitle==1){ //put html title as article title
                         $this->values['title']        = $metadataarr[0] ;
                    }else{
                         if($csvtitle!=''){
                             $this->values['title'] =  $csvtitle;
                         }else {
                             $this->values['title'] = $pagetitle;
                         }

                    }//end if - else

                    $this->values['metadesc']     = $metadataarr[1] ;
                    $this->values['metakey']      = $metadataarr[2] ;
                    // $this->values['title']        = $pagename ;
                    $this->values['alias']        = $pagename ;
                    $this->values['title_alias']  = $pagename ;
                    $this->values['introtext']    = $data;
                    $this->values['sectionid']    = $section_id;
                    $this->values['catid']        = $category_id;
                    $this->values['ordering']     = 1;
                    $this->values['attribs']      = 'show_title=0
                                                    link_titles=0
                                                    show_intro=
                                                    show_section=0
                                                    link_section=0
                                                    show_category=0
                                                    link_category=0
                                                    show_vote=0
                                                    show_author=0
                                                    show_create_date=0
                                                    show_modify_date=0
                                                    show_pdf_icon=0
                                                    show_print_icon=0
                                                    show_email_icon=0
                                                    language=en-GB
                                                    keyref='.$metadataarr[0].'
                                                    readmore=';

                    $this->save();
                    $articleid  = $this->id_value;

                    //menu insertion
                    $this->insert_menu($pagename,$articleid,$urlarr,$home);

                    //joomla redirection
                    $oldurl       = $urlarr[3]."/".$urlarr[4]."/".$pagename.URL_EXTENSION;
                    $newurl       = "index.php?option=com_content&Itemid=$articleid&catid=$category_id&id=$articleid&lang=en&view=article";
                    $aliasurl     = "index.php?option=com_content&Itemid=$articleid&id=$articleid&lang=en&view=article";
                    $htmlpagename = $pagename.URL_EXTENSION;
                    $this->add_redirection($oldurl,$newurl,$aliasurl,$htmlpagename);
               break;

               case 2:
                    //section insertion
                    $section_title = $urlarr[3];
                    $section_id    = $this->check_data_availability('joomla_sections'," where title ='".$section_title."'");
                    if($section_id==0){
                        $section_id  = $this->insert_section($section_title);
                    }
                    //category insertion.

                    $category_title = 'default';
                    $category_id    = $this->check_data_availability('joomla_categories'," where title ='".$category_title."' and section=".$section_id);
                    if($category_id==0){
                        $category_id = $this->insert_category($category_title,$section_id);
                    }

                    //page insertion
                    $pagename = $urlarr[4];
                    $pagename = substr($pagename,0,strrpos($pagename,'.'));
                    $pagehome = substr($pagename,0,strrpos($pagename,'.'));


                    if($pagename=='' || $pagename=='index'){
                         $pagetitle = $urlarr[3]."-".'index';
                         $pagename  = 'index';
                    }else{
                         $pagetitle = $pagename;
                    }

                    $metadataarr = $this->extract_meta($datas);

                    if($istitle==1){ //put html title as article title
                        $this->values['title']        = $metadataarr[0] ;
                    }else{
                         if($csvtitle!=''){
                            $this->values['title'] =  $csvtitle  ;
                         }else {
                            $this->values['title'] = $pagetitle ;
                         }
                    }//end if-else

                    $this->values['metadesc'] = $metadataarr[1] ;
                    $this->values['metakey']  = $metadataarr[2] ;

                    $this->values['alias']        = $pagename ;
                    $this->values['title_alias']  = $pagename ;
                    $this->values['introtext']    = $data;
                    $this->values['sectionid']    = $section_id;
                    $this->values['catid']        = $category_id;
                    $this->values['ordering']     = 1;
                    $this->values['attribs']      = 'show_title=0
                                                    link_titles=0
                                                    show_intro=
                                                    show_section=0
                                                    link_section=0
                                                    show_category=0
                                                    link_category=0
                                                    show_vote=0
                                                    show_author=0
                                                    show_create_date=0
                                                    show_modify_date=0
                                                    show_pdf_icon=0
                                                    show_print_icon=0
                                                    show_email_icon=0
                                                    language=en-GB
                                                    keyref='.$metadataarr[0].'
                                                    readmore=';
                    $this->save();
                    $articleid = $this->id_value;

                    //menu insertion
                    $this->insert_menu($pagename,$articleid,$urlarr,$home);
                    //joomla redirection
                    $oldurl = $urlarr[3]."/".$pagename.URL_EXTENSION;

                    $newurl = "index.php?option=com_content&Itemid=$articleid&catid=$category_id&id=$articleid&lang=en&view=article";
                    $aliasurl = "index.php?option=com_content&Itemid=$articleid&id=$articleid&lang=en&view=article";
                    $htmlpagename = $pagename.URL_EXTENSION;
                    $this->add_redirection($oldurl,$newurl,$aliasurl,$htmlpagename);

               break;
               case 1:
                    //section insertion
                    $section_id = 0;

                    //category insertion.

                    $category_id = 0;
                    //page insertion
                    $pagename = $urlarr[3];

                    $pagename = substr($pagename,0,strrpos($pagename,'.'));
                    $pagehome = substr($pagename,0,strrpos($pagename,'.'));
                    if($pagename==''){
                         $pagename ='index';
                    }
                    $metadataarr = $this->extract_meta($datas);

                    if($istitle==1){ //put html title as article title
                         $this->values['title']        = $metadataarr[0] ;
                    }else{
                         if($csvtitle!=''){
                            $this->values['title']  = $csvtitle;
                         }else {
                            $this->values['title']   = $pagename ;
                         }
                    }//end if - else

                    $this->values['metadesc'] = $metadataarr[1] ;
                    $this->values['metakey']  = $metadataarr[2] ;


                    $this->values['alias']        = $pagename ;
                    $this->values['title_alias']  = $pagename ;
                    $this->values['introtext']    = $data;
                    $this->values['sectionid']    = $section_id;
                    $this->values['catid']        = $category_id;
                    $this->values['ordering']     = 1;
                    $this->values['attribs']      = 'show_title=0
                                                    link_titles=0
                                                    show_intro=
                                                    show_section=0
                                                    link_section=0
                                                    show_category=0
                                                    link_category=0
                                                    show_vote=0
                                                    show_author=0
                                                    show_create_date=0
                                                    show_modify_date=0
                                                    show_pdf_icon=0
                                                    show_print_icon=0
                                                    show_email_icon=0
                                                    language=en-GB
                                                    keyref='.$metadataarr[0].'
                                                    readmore=';
                    $this->save();
                    $articleid = $this->id_value;

                    $this->insert_menu($pagename,$articleid,$urlarr,$home);
                    //joomla redirection
                    $oldurl = $pagename.URL_EXTENSION;

                    $newurl = "index.php?option=com_content&Itemid=$articleid&catid=$category_id&id=$articleid&lang=en&view=article";
                    $aliasurl = "index.php?option=com_content&Itemid=$articleid&id=$articleid&lang=en&view=article";
                    $htmlpagename = $pagename.URL_EXTENSION;
                    $this->add_redirection($oldurl,$newurl,$aliasurl,$htmlpagename);
               break;
               default:
                    if($urlcase==0){
                         $section_id    = 0;
                         //category insertion.

                         $category_id = 0;
                         //page insertion
                         $pagename                     = "index";
                         //  $pagename                     = substr($pagename,0,strrpos($pagename,'.'));
                         $metadataarr = $this->extract_meta($datas);

                         if($istitle==1){ //put html title as article title
                             $this->values['title'] = $metadataarr[0] ;
                         }else{
                              if($csvtitle!=''){
                                 $this->values['title']  = $csvtitle;
                              }else {
                                 $this->values['title']  = $pagename ;
                              }
                              //   $this->values['title'] = $pagename ;
                         }// end if - else

                         $this->values['metadesc']     = $metadataarr[1] ;
                         $this->values['metakey']      = $metadataarr[2] ;


                         $this->values['alias']        = $pagename ;
                         $this->values['title_alias']  = $pagename ;
                         $this->values['introtext']    = $data;
                         $this->values['sectionid']    = $section_id;
                         $this->values['catid']        = $category_id;
                         $this->values['ordering']     = 1;
                         $this->values['attribs']      = 'show_title=0
                                                        link_titles=0
                                                        show_intro=
                                                        show_section=0
                                                        link_section=0
                                                        show_category=0
                                                        link_category=0
                                                        show_vote=0
                                                        show_author=0
                                                        show_create_date=0
                                                        show_modify_date=0
                                                        show_pdf_icon=0
                                                        show_print_icon=0
                                                        show_email_icon=0
                                                        language=en-GB
                                                        keyref='.$metadataarr[0].'
                                                        readmore=';
                         $this->save();
                         $articleid = $this->id_value;

                         //menu insertion
                         //$this->insert_menu($pagename,$articleid,1);


                         $this->insert_menu($pagename,$articleid,$urlarr,$home);

                         //joomla redirection
                         $oldurl = $pagename.URL_EXTENSION;

                         $newurl   = "index.php?option=com_content&Itemid=$articleid&catid=$category_id&id=$articleid&lang=en&view=article";
                         $aliasurl = "index.php?option=com_content&Itemid=$articleid&id=$articleid&lang=en&view=article";
                         $htmlpagename = $pagename.URL_EXTENSION;
                         $this->add_redirection($oldurl,$newurl,$aliasurl,$htmlpagename);
                    }else{
                         //section insertion
                         $section_title = $urlarr[3];

                         $section_id = $this->check_data_availability('joomla_sections'," where title ='".$section_title."'");
                         if($section_id==0){
                             $section_id =$this->insert_section($section_title);

                         }
                         //category insertion.
                         $category_title = $urlarr[4];

                         $category_id =$this->check_data_availability('joomla_categories'," where title ='".$category_title."' and section=".$section_id);
                         if($category_id==0){
                             $category_id = $this->insert_category($category_title,$section_id);
                         }
                         //page insertion
                         $pagename    = $urlarr[count($urlarr)-1];
                         $pagename    = substr($pagename,0,strrpos($pagename,'.'));
                         $metadataarr = $this->extract_meta($datas);

                         $this->values['metadesc'] = $metadataarr[1] ;
                         $this->values['metakey']  = $metadataarr[2] ;

                         if($istitle==1){ //put html title as article title
                             $this->values['title'] = $metadataarr[0] ;
                         }else{
                              if($csvtitle!=''){
                                  $this->values['title']  = $csvtitle;
                              }else {
                                  $this->values['title']  = $pagename ;
                              }
                              // $this->values['title']       = $pagename ;
                         }//end if - else
                         $this->values['alias']        = $pagename ;
                         $this->values['title_alias']  = $pagename ;
                         $this->values['introtext']    = $data;
                         $this->values['sectionid']    = $section_id;
                         $this->values['catid']        = $category_id;
                         $this->values['ordering']     = 1;
                         $this->values['attribs']      = 'show_title=0
                                                        link_titles=0
                                                        show_intro=
                                                        show_section=0
                                                        link_section=0
                                                        show_category=0
                                                        link_category=0
                                                        show_vote=0
                                                        show_author=0
                                                        show_create_date=0
                                                        show_modify_date=0
                                                        show_pdf_icon=0
                                                        show_print_icon=0
                                                        show_email_icon=0
                                                        language=en-GB
                                                        keyref='.$metadataarr[0].'
                                                        readmore=';
                         $this->save();

                         $articleid = $this->id_value;

                         $this->insert_menu($pagename,$articleid,$urlarr,$home);
                         $makeurl = $inurl;

                         for($s=3;$s<$arrlength-1;$s++){
                             $makeurl .= "/".$arrlength[$s];
                         }
                         //joomla redirection
                         $oldurl  = $makeurl."/".$pagename.URL_EXTENSION;
                         $newurl  ="index.php?option=com_content&Itemid=$articleid&catid=$category_id&id=$articleid&lang=en&view=article";
                         $aliasurl = "index.php?option=com_content&Itemid=$articleid&id=$articleid&lang=en&view=article";
                         $htmlpagename = $pagename.URL_EXTENSION;
                         $this->add_redirection($oldurl,$newurl,$aliasurl,$htmlpagename);
                    }// end if - else
                break;
          } //end switch
     } //end function add_article
} //end class article